package com.glela.order.service.impl;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.glela.order.mapper.CommisionMapper;
import com.glela.order.mapper.OrderDetailMapper;
import com.glela.order.mapper.OrderInfoMapper;
import com.glela.order.model.CommissionManage;
import com.glela.order.service.CommissionManageService;
import com.glela.platform.mapper.UserBankMapper;
import com.glela.platform.mapper.UserJournalMapper;
import com.glela.platform.mapper.UserMapper;
import com.glela.platform.service.UnifiedTreatmentService;

@Service("commissionManageService")
public class CommissionManageServiceImpl implements CommissionManageService {

	@Resource
	private UserBankMapper userBankMapper;
	@Resource
	private UserMapper userMapper;
	@Resource
	private OrderInfoMapper orderInfoMapper;
	@Resource
	private UserJournalMapper userJournalMapper;
	@Resource
	private CommisionMapper commisionMapper;
	@Resource
	private UnifiedTreatmentService unifiedTreatmentService;
	

	@Resource
	private OrderDetailMapper orderDetailMapper;
	@Override
	public CommissionManage selectCommissionManage(long userId) {
		// TODO Auto-generated method stub
		CommissionManage commissionManage = new CommissionManage();
		commissionManage.setWithdrawMoney(userMapper.selectUserEntityById(userId).getMoney());// 可提现金额`
		commissionManage.setBankCount(userBankMapper.selectUserBankcount(userId));// 银行卡张数
		commissionManage.setCommission(commisionMapper.selectCommisionSumFee(userId));// 累计获得佣金
		commissionManage.setOrderCount(commisionMapper.selectCommisionOrderInfoIdByUserIdTwo(userId));// 订单数量
		commissionManage.setSaleroom(unifiedTreatmentService.userSalesAmountTotal(userId));// 总销售金额
		List<Integer> IntegerList=commisionMapper.selectCommisionOrderInfoIdByUserId(userId,0,1000);
		if (IntegerList.size()<=0) {
			IntegerList.add(0);
		}
		commissionManage.setTotalPrice(orderInfoMapper.selectcountorderinfototalfee(IntegerList));// 交易中的订单金额
		/*// 1、查出有多少人佣金比你少，设变量为A
		// int lessThanYouNum = commisionMapper.selectUserNumWhereLessThanYou(userId);
		// 2、统计有多少个人有佣金>0，设变量为B
		// int totalNum = commisionMapper.selectUserNumWhereHasCommision();
		// 3、用佣金比你少的总人数，除以有佣金的总人数，即为A/B
		if (totalNum == 0) {
			// 分母不能为0，如果分母偏偏是0
			commissionManage.setDefeatPeople("0");
			return commissionManage;
		}
		// double defeatPeople =  (double) lessThanYouNum/ (double) totalNum;
		// String str=String.format("%.2f",defeatPeople);
		// double qq=Double.parseDouble(str);
		// double inte=qq*100/2;
		// String rer=Double.toString(inte);
		// commissionManage.setDefeatPeople(rer.substring(0, 1));//击败的达人百分比
		if(commissionManage.getDefeatPeople().equals("n")){
			commissionManage.setDefeatPeople("0");
		}*/
		commissionManage.setDefeatPeople("0");
		return commissionManage;
	}
}